<?php

class Producto extends DataMapper
{
	public $table = 'productos';
	public $model = 'producto';
	public $has_one = array('marca','categoria','origen','medida');
	public $has_many = array('precio','historicoproducto','venta-detalle','lote','movimiento');
	
	public function __construct($id = null)
	{
		parent::__construct($id);
	}

	public function get_id_from_code($codigo){
		if (is_numeric($codigo[0]))
			$search_by = 'ean13';
		else
			$search_by = 'codigo';
		
		$query = $this->db->get_where($this->table, array($search_by => $codigo));

		$arr = $query->result();
		if ($query->num_rows() > 0)
			return $arr[0]->id;
		else
			return 0;
	}
}

// End of file producto.php
/* Location ./application/models/producto.php */